package com.easyattendance.model;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name="TBL_ASSIGNMENT")
@IdClass(AssignmentPK.class)
public class Assignment implements Comparable<Assignment> {
	
	@Id
	@Column(name="assignment_id",length=15)
	private String assignment_id;
	
	@Id
	@GenericGenerator(name="subject_id",strategy="foreign")
	@Column(name="subject_id",length=6,nullable=false)
	private String subject_id;
	
	@Id
	@GenericGenerator(name="class_id",strategy="foreign")
	@Column(name="class_id",length=15,nullable=false)
	private String class_id;
	
	@Column(name="assignment_name",length=32,nullable=false)
	private String assignment_name;
	
	/* many to one mappings of Assignment */
	
	@ManyToOne
	@JoinColumn(name="subject_id",insertable=false,updatable=false)
	private Subject subject;
	
	@ManyToOne
	@JoinColumn(name="class_id",insertable=false,updatable=false)
	private Class classObj;
	
	@ManyToOne
	@JoinColumn(name="teacher_id")
	private Teacher teacher;
	
	/* One to many mappings of Assignment */
	
	@OneToMany(mappedBy="assignment")
	private Set<AssignmentStudent> assignmentStudent;	
	
	@Column(name="physical_path",nullable=false,length=255)
	private String physical_path;
	
	@Column(name="assignment_given_date",nullable=false)
	private Date assignment_given_date;
	
	@Column(name="submission_date",nullable=false)
	private Date submission_date;

	public Assignment() {
		super();
	}
	
	

	public Assignment(String assignment_id, String subject_id, String class_id,
			String assignment_name, String physical_path,
			Date assignment_given_date, Date submission_date) {
		super();
		this.assignment_id = assignment_id;
		this.subject_id = subject_id;
		this.class_id = class_id;
		this.assignment_name = assignment_name;
		this.physical_path = physical_path;
		this.assignment_given_date = assignment_given_date;
		this.submission_date = submission_date;
	}



	public Assignment(String assignment_id, String subject_id, String class_id, String assignment_name,
			Subject subject, Class classObj, Teacher teacher,
			Set<AssignmentStudent> assignmentStudent, String physical_path,
			Date assignment_given_date, Date submission_date) {
		super();
		this.assignment_id = assignment_id;
		this.subject_id = subject_id;
		this.class_id = class_id;
		this.assignment_name = assignment_name;
		this.subject = subject;
		this.classObj = classObj;
		this.teacher = teacher;
		this.assignmentStudent = assignmentStudent;
		this.physical_path = physical_path;
		this.assignment_given_date = assignment_given_date;
		this.submission_date = submission_date;
	}

	public String getAssignment_id() {
		return assignment_id;
	}

	public void setAssignment_id(String assignment_id) {
		this.assignment_id = assignment_id;
	}

	public String getSubject_id() {
		return subject_id;
	}

	public void setSubject_id(String subject_id) {
		this.subject_id = subject_id;
	}

	public String getClass_id() {
		return class_id;
	}

	public void setClass_id(String class_id) {
		this.class_id = class_id;
	}

	public Subject getSubject() {
		return subject;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public Class getClassObj() {
		return classObj;
	}

	public void setClassObj(Class classObj) {
		this.classObj = classObj;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public Set<AssignmentStudent> getAssignmentStudent() {
		return assignmentStudent;
	}

	public void setAssignmentStudent(Set<AssignmentStudent> assignmentStudent) {
		this.assignmentStudent = assignmentStudent;
	}

	public String getPhysical_path() {
		return physical_path;
	}

	public void setPhysical_path(String physical_path) {
		this.physical_path = physical_path;
	}

	public Date getAssignment_given_date() {
		return assignment_given_date;
	}

	public void setAssignment_given_date(Date assignment_given_date) {
		this.assignment_given_date = assignment_given_date;
	}

	public Date getSubmission_date() {
		return submission_date;
	}

	public void setSubmission_date(Date submission_date) {
		this.submission_date = submission_date;
	}

	public String getAssignment_name() {
		return assignment_name;
	}

	public void setAssignment_name(String assignment_name) {
		this.assignment_name = assignment_name;
	}

	@Override
	public int compareTo(Assignment arg0) {
		// TODO Auto-generated method stub
		return 0;
	} 
	
	/* Comparator interface to sort list of Assignments by Class Id */
   public static class SortAssignmentByClass implements Comparator<Assignment> {

		@Override
		public int compare(Assignment assign1, Assignment assign2) {
			return assign1.class_id.compareTo(assign2.class_id);
		}
   }

	
}
